home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / yerk / mps231ss.hqx / Mops source / Asm Source / Dictionary < prev    next >
Text File  |  1993-02-02  |  4KB  |  168 lines

  1. \ DICTIONARY CLASS                  Reese Warner                4/85
  2. \  Useful for symbol tables, et. al.
  3.  
  4. 0 -> dlevel
  5.  
  6.  
  7. :class    DICTELT  super{ string }
  8.  
  9.     objHandle    OBJHDL    \ Handle to the object associated with the string.
  10.  
  11. :m PUTOBJHDL:    put: objHdl  ;m
  12. :m GETOBJ:        obj: objHdl  ;m
  13. :m RELEASE:
  14.     release: super
  15.     nil?: objHdl  ?EXIT
  16.     obj: objHdl  release: **   release: objHdl  ;m
  17.  
  18. :m PRINT:    4 spaces  print: super  3 spaces  obj: objHdl  print: **  ;m
  19.  
  20. ;class
  21.  
  22.  
  23. objPtr    HLOBJ    class_is  handleList
  24. objPtr    DEOBJ    class_is  dictElt
  25.  
  26.  
  27. :class    DICTIONARY  super{ handleArray }
  28.  
  29. private
  30.  
  31. \ SEARCHLIST - does the main work of methods ENTER & QUERY. Intended to be
  32. \   a private method for class DICTIONARY. Searchs the handleList object
  33. \   HLobj for a dictElt object matching the given string.  If found, returns
  34. \   the matching dictElt object and true, otherwise just false.
  35.  
  36. :m SEARCHLIST:   { HLob strObj -- DEobj T  |  -- F }
  37.     HLob -> HLobj
  38.     BEGIN  each: HLobj
  39.     WHILE
  40.         ( obj addr )  -> DEobj
  41.         get: strObj  get: DEobj  s=
  42.         IF  unEach: HLobj  DEobj true  EXIT  THEN
  43.     REPEAT
  44.     false  ;m
  45.  
  46. public
  47.  
  48. \ QUERY - returns pointer to the object associated with strObj in the
  49. \ dictionary.  If string is not found, then nilP is returned.
  50.  
  51. :m QUERY:   { strObj \ idx -- ^obj }
  52.  
  53.     get: strObj str255  wHash  limit: self  mod  -> idx
  54.     idx  select: self
  55.     nil?: self  IF  nilP  EXIT  THEN
  56.     obj: self  -> HLobj
  57.     size: HLobj  NIF  nilP  EXIT  THEN
  58.     HLobj strObj searchList: self
  59.     IF
  60.         -> DEobj
  61.         getObj: DEobj
  62.     ELSE
  63.         nilP
  64.     THEN
  65.     unlock: self  ;m
  66.  
  67.  
  68. \ ENTER - puts the string and value into the dictionary. If the string is
  69. \  already in the dictionary then it changes the value to the new value.
  70.  
  71. :m ENTER:  { hdlObj strObj \ idx -- }
  72.  
  73.     get: strObj  str255  wHash  limit: super  mod -> idx
  74.     idx  select: self
  75.     nil?: self
  76.     IF  ( Need new handleList object )
  77.         ['] handleList  newObj: self    obj: self  -> HLobj
  78.         ['] dictElt  newObj: HLobj    obj: HLobj -> DEobj
  79.         strObj ->: DEobj
  80.         get: hdlObj  putObjHdl: DEobj
  81.     ELSE
  82.         obj: self  -> HLobj
  83.         HLobj strObj searchList: self
  84.         IF  ( In already - change value )
  85.             -> DEobj
  86.             get: hdlObj  putObjHdl: DEobj
  87.         ELSE
  88.             ['] dictElt  newObj: HLobj
  89.             obj: HLobj -> DEobj
  90.             strObj ->: DEobj
  91.             get: hdlObj  putObjHdl: DEobj
  92.         THEN
  93.     THEN
  94.     unlock: HLobj  unlock: self  ;m
  95.  
  96.  
  97. \ EXEC: - for every element in the dictionary exec: executes routine with the 
  98. \  associated value and an addr/len pair representing the hashed string as 
  99. \  an argument
  100.  
  101. \ :m EXEC:  { routine -- }
  102. \    limit: self 0 
  103. \    DO
  104. \        i  select: self
  105. \        nil?: self
  106. \        NIF
  107. \            obj: self  -> HLobj
  108. \            start: HLobj
  109. \            BEGIN
  110. \                obj: HLobj  -> DEobj
  111. \                getObj: DEobj  get: DEobj
  112. \                routine  execute
  113. \                unlock: HLobj
  114. \                next?: HLobj
  115. \            NUNTIL
  116. \            unlock: self
  117. \        THEN
  118. \    LOOP  ;m
  119.  
  120.  
  121. :m RELEASE:
  122.     release: super  limit  put: size  ;m
  123.  
  124. :m CLASSINIT:
  125.     limit  put: size
  126.     classinit: super  ;m
  127.  
  128. ;class
  129.  
  130. 25    dictionary    SYMTAB
  131.  
  132. endload
  133.  
  134. \ Testing
  135. +echo
  136.  
  137. 10 dictionary dd
  138. string s  " hello" put: s  string t  " qqq" put: t
  139. handle h
  140.  
  141. ' var  newObj: h
  142. \ h s enter: dd
  143.  
  144. endload
  145.  
  146. :class    SYMBOLS        super(    dictionary  )
  147.  
  148. \ QUERY - returns value associated with String in dictionary and FoundFlag. If
  149. \ string is not found in dictionary, then 0 0 is returned. Needed for SymTab
  150. \ where 0 is valid value.
  151.  
  152. :m QUERY:   { strObj \ idx HLobj DEobj -- val b }
  153.  
  154.     get: strObj str255  wHash  limit: self  mod  -> idx
  155.     idx  select: self
  156.     nil?: self  IF  0  false  EXIT  THEN
  157.     obj: self  -> HLobj
  158.     size: HLobj  NIF  0  false  EXIT  THEN
  159.     HLobj strObj searchList: self
  160.     IF
  161.         -> DEobj
  162.         getData: DEobj  true
  163.     ELSE
  164.         0  false
  165.     THEN  ;m
  166.  
  167. ;class
  168.